/*
 * @Description: 数组创建
 * @Author: zzj
 * @Date: 2021-09-06 14:32:50
 * @LastEditors: zzj
 * @LastEditTime: 2021-09-13 14:29:13
 */

//数组的创建
var arr1 = new Array(5);  //在创建时，初始化数组的长度
arr1[0] = "zhangsan";
arr1[1] = "lisi";
arr1[2] = "wangwu";
console.log(arr1);
console.log(arr1.length);

//字面量创建[]  对象：{}
var arr2 = ["zhangsan","lisi","wangwu"];
console.log(arr2);

//创建一个数组中包含1-100
var nums = [];
for (var i=0;i<100;i++){
    nums[i] = i+1;
}
console.log(nums)

//数组遍历(将每一个成员提取一次)   循环提取数组成员
//for    for...in
for (var i=0;i<nums.length;i++){
    // console.log(nums[i]);
    nums[i] = "数字：" + nums[i]; //可以做一些操作
}
console.log(nums);

for(var k in nums){
    console.log(nums[k]);
}

//数组也为引用数据类型{}
//数组的浅拷贝
var arr3 = [1,2,3];
var arr4 = arr3;
arr4[3] = 4;
console.log(arr3);
//数组的深拷贝
var arr5 = [];  //创建新数组,然后把数组3的成员遍历，一个一个加入到数组5中
for(var k in arr3){   
    arr5.push(arr3[k]);  //push:在数组5的末尾添加成员
}
var arr6 = arr3.concat(4,5,6);  //数组拼接函数，返回新数组
arr6.push(4)
console.log(arr5,arr6)
//将可迭代对象或类数组转换为真数组
var obj = {
    "0":"zhangsna",
    "1":"lisi",
    "2":"wangwu",
    "length":3
}
console.log(obj);
console.log(Array.from(obj));
var arr_obj = Array.from(obj);
arr_obj.push("zhaoliu");
console.log(arr_obj);
//字符串和数组默认是可迭代的对象








